home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / doors_2 / ringchk1.zip / RINGCHEK.C next >
C/C++ Source or Header  |  1992-08-17  |  3KB  |  87 lines

  1.  
  2. /* This program waits 7 seconds for a RING from the modem and exits with */
  3. /*  an errorlevel of 1 if gets one within that time.  Also handles KB:.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <process.h>
  9. #include <conio.h>
  10. #include <time.h>
  11. #include <dos.h>  /* Dos-specific functions are used to get date/time. */
  12.  
  13. #include "common.h"
  14. #include "modem.h"     /* Routines for accessing the modem. */
  15.  
  16.  
  17. /*---------------------------- The program! ----------------------------*/
  18. int main(int argc, char *argv[])
  19. {
  20. char arg_port[64],arg_baud[64];
  21. time_t ending_time;
  22. int the_char;
  23.  
  24. printf("RINGCHEK -- Alton Moore -- Fidonet 1:397/5264, WWIVnet 1@1042\n");
  25. if (argc != 3)
  26.   {
  27.   printf("?Illegal number of arguments.%c\n",BELL_string[0]);
  28.   printf("\nSpecify com port, then baud rate on the command line, eg:\n\n");
  29.   printf("  RINGCHEK 2 19200\n\n");
  30.   printf("Error levels returned:  0 -- No RING; no keyboard abort (SUCCESS)\n");
  31.   printf("                        1 -- RING was detected from modem\n");
  32.   printf("                        2 -- Key pressed to abort callout\n");
  33.   printf("                        9 -- Parameter or program's error\n");
  34.   printf("\nExiting with errorlevel 9....\n");
  35.   return(9);
  36.   }
  37. strcpy(arg_port,argv[1]);
  38. strcpy(arg_baud,argv[2]);
  39. modem_port  = atoi(arg_port);
  40. modem_speed = atoi(arg_baud);
  41. if (initSerial(modem_port,modem_speed,modem_parity,modem_bits,modem_stopbits))
  42.   {
  43.   printf("?Couldn't initialize serial port; exiting with errorlevel 9!\n");
  44.   return(9);
  45.   }
  46. printf("Waiting 7 seconds for RING from modem.  Hit space bar to\n");
  47. printf("hurry up or press any other key to abort next operation.\n");
  48.  
  49. trace_start("RING");
  50. ending_time = time(NULL) + 7;      /* Wait for 7 seconds.... */
  51. while (time(NULL) < ending_time)
  52.   {
  53.   if (kbhit())
  54.     {
  55.     deinitSerial(0);
  56.     trace_stop_all();
  57.     if (getch() == ' ')
  58.       {
  59.       printf("Quitting and exiting with errorlevel 0!\n");
  60.       return(0);
  61.       }
  62.     else
  63.       {
  64.       printf("Key pressed; aborting and exiting with errorlevel 2!\n");
  65.       return(2);
  66.       }
  67.     }
  68.   the_char = port_in();             /* Anything from the modem? */
  69.   if (the_char != -1)
  70.     trace_process_received_character(the_char);
  71.   if (trace_fired("RING"))
  72.     {
  73.     printf("RING detected from modem; exiting with errorlevel 1!\n");
  74.     trace_stop_all();
  75.     trash_modem_output(modem_port,0);
  76.     deinitSerial(0);
  77.     return(1);
  78.     }
  79.   }
  80. printf("Nothing detected; exiting with errorlevel 0.\n");
  81. trace_stop_all();
  82. deinitSerial(0);
  83. return(0);
  84. }
  85.  
  86.  
  87.